package commons;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class Assertions 
{
	private Set<String> messages = new HashSet<String>();
	private boolean checkpoint;

	public void assertTrue(String message, boolean actual) 
	{	if (!actual)
		{	addMessage(message);
		}
	}
	
	public void assertFalse(String message, boolean actual) 
	{	if (actual)
		{	addMessage(message);
		}
	}
	
	public void assertNull(String message, Object object) 
	{	if (object != null)
		{	addMessage(message);
		}
	}
	
	public void assertNotNull(String message, Object object) 
	{	if (object == null)
		{	addMessage(message);
		}
	}
	
	public void assertEquals(String message, double expected, double actual, double epsilon) 
	{	if (Math.abs(expected - actual) > epsilon)
		{	addMessage(message);
		}
	}
	
	public void assertEquals(String message, int expected, int actual) 
	{	if (expected != actual)
		{	addMessage(message);
		}
	}
	
	public void assertEquals(String message, String expected, String actual) 
	{	if (actual == null || !expected.equals(actual))
		{	addMessage(message);
		}
	}
	
	public Set<String> getMessages() 
	{	return messages;
	}

	public void checkpoint() 
	{	this.checkpoint  = true;
	}
	
	public boolean stateChanged()
	{	return !checkpoint;
	}
	
	private void addMessage(String message) 
	{	messages.add(message);
		checkpoint = false;
	}
}
